<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 10/2/18
 * Time: 6:32 PM
 */

namespace common\models\db;


use common\components\tools\ArrayHelper;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;

/**
 * Class DocuComment
 * @package common\models\db
 *
 * @property Docu $docu
 * @property User $createdBy
 * @property DocuCommentReply[] $docuCommentReplies
 */
class DocuComment extends \common\models\db\tables\DocuComment
{
    const STATUS_DEFAULT = 10;

    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::class,
            ],
            'blameable' => [
                'class' => BlameableBehavior::class,
            ],
        ];
    }

    public function rules()
    {
        $a1 = parent::rules();
        foreach ($a1 as $k => $v){
            if ($v[1] == 'required'){
                if (is_array($v[0])){
                    $a1[$k][0] = array_diff($a1[$k][0], ['created_at', 'updated_at', 'created_by', 'updated_by']);
                }
            }
        }
        $rules = [
            ['body', 'string'],
        ];
        $rules = ArrayHelper::merge($a1, $rules);
        return $rules;
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocu()
    {
        return $this->hasOne(Docu::className(), ['id' => 'docu_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuCommentReplies()
    {
        return $this->hasMany(DocuCommentReply::className(), ['docu_comment_id' => 'id']);
    }
}